package cn.com.ghy.android.widget.chat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import cn.com.ghy.android.bean.CustomerInfoBean;
import cn.com.ghy.android.bean.OrderDetailBean;
import cn.com.ghy.android.widget.R;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:客户详细信息
 * @author wuz  @date 2011-5-13 09:43:39
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class CustomerDetailInfoList extends Activity {

	private int[] colWidth = null;
	private String[] colName = null;
	
	private Intent intent = null;
	private Bundle bundle = null;
	private CustomerInfoBean customerInfo = null;
	private CustomerDetailInfoExcelView excel = null;
	private Button btnCreateOrder = null;
	
	private List<OrderDetailBean> listOrderDetail = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.customer_detail_info_list);
		getSession();
		setExcelTitle();
		setExcelContent();
		((LinearLayout) findViewById(R.id.layCustomerDetailInfoList)).addView(excel.getView());
		
		btnCreateOrder = (Button) this.findViewById(R.id.btnCreateOrder);
		btnCreateOrder.setOnClickListener(btnListener);
	}
	
	@SuppressWarnings("unchecked")
	private void getSession() {
		intent = this.getIntent();
		customerInfo = (CustomerInfoBean) intent.getSerializableExtra("customerInfo");
		listOrderDetail = (List<OrderDetailBean>) intent.getSerializableExtra("listOrderDetail");
	}
    
    private View.OnClickListener btnListener = new View.OnClickListener() {
		public void onClick(View v) {
			switch(v.getId()) {
				case R.id.btnCreateOrder :
					bundle = new Bundle();
					bundle.putSerializable("customerInfo", customerInfo);
					bundle.putSerializable("listOrderDetail", (Serializable) listOrderDetail);
					intent = new Intent(CustomerDetailInfoList.this, OrderInfo.class);
					intent.putExtras(bundle);
					CustomerDetailInfoList.this.startActivity(intent);
					break;
			}
		}
	};
	
	private void setExcelTitle() {
		int totalWidth = this.getWindowManager().getDefaultDisplay().getWidth();
		colWidth = new int[]{ totalWidth / 4, (int)(totalWidth)};
		colName = new String[]{"资料名称", "资料信息"};
		excel = new CustomerDetailInfoExcelView(CustomerDetailInfoList.this, 40, colName, colWidth);
		excel.setTitle();
	}
	
	private void setExcelContent() {
		List<String[]> list = new ArrayList<String[]>();
		String[] value = new String[]{"客户编号", customerInfo.getPartner()};
		list.add(value);
		value = new String[]{"客户名称", customerInfo.getName_org1()};
		list.add(value);
		value = new String[]{"营业所", customerInfo.getLoginInfo().getSaofname()};
		list.add(value);
		value = new String[]{"省", customerInfo.getProvname()};
		list.add(value);
		value = new String[]{"市", customerInfo.getCityname()};
		list.add(value);
		value = new String[]{"县区", customerInfo.getZonename()};
		list.add(value);
		value = new String[]{"街道", customerInfo.getJdb()};
		list.add(value);
		value = new String[]{"联系地址", customerInfo.getStreet()};
		list.add(value);
		value = new String[]{"联系人", customerInfo.getLxr()};
		list.add(value);
		value = new String[]{"联系电话", customerInfo.getLxdh()};
		list.add(value);
		value = new String[]{"客户类型", customerInfo.getCyname()};
		list.add(value);
		value = new String[]{"大通路类型", customerInfo.getCk1name()};
		list.add(value);
		value = new String[]{"交易模式", customerInfo.getCk2name()};
		list.add(value);
		value = new String[]{"连锁状态", customerInfo.getQdname()};
		list.add(value);
		value = new String[]{"业态", customerInfo.getYtname()};
		list.add(value);
		value = new String[]{"门店面积", customerInfo.getMdmj()};
		list.add(value);
		value = new String[]{"客户等级", customerInfo.getDengji()};
		list.add(value);
		value = new String[]{"纸品容量", customerInfo.getCapacity()};
		list.add(value);
		if (null != customerInfo.getJxsid() && null != customerInfo.getJxsname()) {
			value = new String[]{"经销商编号", customerInfo.getJxsid()};
			list.add(value);
			value = new String[]{"经销商名称", customerInfo.getJxsname()};
			list.add(value);
		} else if(null != customerInfo.getFxsid() && null != customerInfo.getFxsname()) {
			value = new String[]{"分销商编号", customerInfo.getFxsid()};
			list.add(value);
			value = new String[]{"分销商名称", customerInfo.getFxsname()};
			list.add(value);
		}
		value = new String[]{"备注", customerInfo.getRemark()};
		list.add(value);
		excel.createAdapter(list);
	}

}
